package com.cd.common.util;//package com.lqq.main.utils;
//
//import org.apache.commons.lang.StringUtils;
//import org.apache.http.HttpResponse;
//import org.apache.http.HttpStatus;
//import org.apache.http.client.methods.HttpGet;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.util.EntityUtils;
//import org.springframework.util.CollectionUtils;
//
//import java.nio.charset.StandardCharsets;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//
//public class HttpUtil {
//
//    /**
//     * GET请求
//     *
//     * @param url    URL
//     * @param params 参数
//     * @return 响应结果
//     * @throws Exception HTTP异常
//     */
//    public static String sendGet(String url, Map<String, String> params) throws Exception {
//        HttpGet httpGet = null;
//        String body;
//        try {
//            CloseableHttpClient httpClient = HttpClients.createDefault();
//            List<String> mapList = new ArrayList<>();
//            if (params != null) {
//                for (Map.Entry<String, String> entry : params.entrySet()) {
//                    mapList.add(entry.getKey() + "=" + entry.getValue());
//                }
//            }
//            if (!CollectionUtils.isEmpty(mapList)) {
//                url = url + "?";
//                String paramsStr = StringUtils.join(mapList, "&");
//                url = url + paramsStr;
//            }
//            httpGet = new HttpGet(url);
//            httpGet.setHeader("Content-type", "application/json; charset=utf-8");
//            httpGet.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//
//            HttpResponse response = httpClient.execute(httpGet);
//
//            int statusCode = response.getStatusLine().getStatusCode();
//            body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
//            if (statusCode != HttpStatus.SC_OK) {
//                body = "RESPONSE HTTP STATUS [" + statusCode + "] RESPONSE DATA [" + body + "]";
//                throw new RuntimeException(body);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw e;
//        } finally {
//            if (httpGet != null) {
//                httpGet.releaseConnection();
//            }
//        }
//        return body;
//    }
//
//    /**
//     * GET请求
//     *
//     * @param url    URL
//     * @param params 参数
//     * @return 响应结果
//     * @throws Exception HTTP异常
//     */
//    public static String sendGet(String url, Map<String, String> params, Map<String, String> header) throws Exception {
//        HttpGet httpGet = null;
//        String body;
//        try {
//            CloseableHttpClient httpClient = HttpClients.createDefault();
//            List<String> mapList = new ArrayList<>();
//            if (params != null) {
//                for (Map.Entry<String, String> entry : params.entrySet()) {
//                    mapList.add(entry.getKey() + "=" + entry.getValue());
//                }
//            }
//            if (!CollectionUtils.isEmpty(mapList)) {
//                url = url + "?";
//                String paramsStr = StringUtils.join(mapList, "&");
//                url = url + paramsStr;
//            }
//            httpGet = new HttpGet(url);
//            httpGet.setHeader("Content-type", "application/json; charset=utf-8");
//            httpGet.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//            if (header != null) {
//                for (Map.Entry<String, String> entry : header.entrySet()) {
//                    httpGet.setHeader(entry.getKey(), entry.getValue());
//                }
//            }
//            HttpResponse response = httpClient.execute(httpGet);
//
//            int statusCode = response.getStatusLine().getStatusCode();
//            body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
//            if (statusCode != HttpStatus.SC_OK) {
//                body = "RESPONSE HTTP STATUS [" + statusCode + "] RESPONSE DATA [" + body + "]";
//                throw new RuntimeException(body);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw e;
//        } finally {
//            if (httpGet != null) {
//                httpGet.releaseConnection();
//            }
//        }
//        return body;
//    }
//
//    /**
//     * POST请求
//     *
//     * @param url  URL
//     * @param json 参数JSON字符串
//     * @return 响应结果
//     * @throws Exception HTTP异常
//     */
//    public static String sendPostJson(String url, String json) throws Exception {
//        HttpPost httpPost = null;
//        String body;
//        try {
//            CloseableHttpClient httpClient = HttpClients.createDefault();
//            httpPost = new HttpPost(url);
//            httpPost.setHeader("Content-type", "application/json; charset=utf-8");
//            httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//
//            StringEntity entity = new StringEntity(json, StandardCharsets.UTF_8);
//            entity.setContentEncoding("UTF-8");
//            entity.setContentType("application/json");
//            httpPost.setEntity(entity);
//            HttpResponse response = httpClient.execute(httpPost);
//
//            int statusCode = response.getStatusLine().getStatusCode();
//            body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
//            if (statusCode != HttpStatus.SC_OK) {
//                body = "RESPONSE HTTP STATUS [" + statusCode + "] RESPONSE DATA [" + body + "]";
//                throw new RuntimeException(body);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw e;
//        } finally {
//            if (httpPost != null) {
//                httpPost.releaseConnection();
//            }
//        }
//        return body;
//    }
//
//    /**
//     * POST请求
//     *
//     * @param url  URL
//     * @param json 参数JSON字符串
//     * @return 响应结果
//     * @throws Exception HTTP异常
//     */
//    public static String sendPostJson(String url, String json, Map<String, String> header) throws Exception {
//        HttpPost httpPost = null;
//        String body;
//        try {
//            CloseableHttpClient httpClient = HttpClients.createDefault();
//            httpPost = new HttpPost(url);
//            httpPost.setHeader("Content-type", "application/json; charset=utf-8");
//            httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//            if (header != null) {
//                for (Map.Entry<String, String> entry : header.entrySet()) {
//                    httpPost.setHeader(entry.getKey(), entry.getValue());
//                }
//            }
//
//            StringEntity entity = new StringEntity(json, StandardCharsets.UTF_8);
//            entity.setContentEncoding("UTF-8");
//            entity.setContentType("application/json");
//            httpPost.setEntity(entity);
//            HttpResponse response = httpClient.execute(httpPost);
//
//            int statusCode = response.getStatusLine().getStatusCode();
//            body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
//            if (statusCode != HttpStatus.SC_OK) {
//                body = "RESPONSE HTTP STATUS [" + statusCode + "] RESPONSE DATA [" + body + "]";
//                throw new RuntimeException(body);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw e;
//        } finally {
//            if (httpPost != null) {
//                httpPost.releaseConnection();
//            }
//        }
//        return body;
//    }
//
//    /**
//     * POST请求
//     *
//     * @param url   URL
//     * @param param 参数字符串
//     * @return 响应结果
//     * @throws Exception HTTP异常
//     */
//    public static String sendFormJson(String url, String param) throws Exception {
//        HttpPost httpPost = null;
//        String body;
//        try {
//            CloseableHttpClient httpClient = HttpClients.createDefault();
//            httpPost = new HttpPost(url);
//            httpPost.setHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
//            httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//
//            StringEntity entity = new StringEntity(param, StandardCharsets.UTF_8);
//            entity.setContentEncoding("UTF-8");
//            entity.setContentType("application/x-www-form-urlencoded");
//            httpPost.setEntity(entity);
//            HttpResponse response = httpClient.execute(httpPost);
//
//            int statusCode = response.getStatusLine().getStatusCode();
//            body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
//            if (statusCode != HttpStatus.SC_OK) {
//                body = "RESPONSE HTTP STATUS [" + statusCode + "] RESPONSE DATA [" + body + "]";
//                throw new RuntimeException(body);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw e;
//        } finally {
//            if (httpPost != null) {
//                httpPost.releaseConnection();
//            }
//        }
//        return body;
//    }
//}